package com.matt.sooncleaner.junk;

import android.content.ContentUris;
import android.database.Cursor;
import android.net.Uri;
import android.provider.MediaStore;

import com.blankj.utilcode.util.Utils;

public class MediaUtils {

    public static String getPath(String uriPath) {
        String[] projection = {MediaStore.Video.Media.DATA};
        String[] pathArray = uriPath.split("/");
        long id = Long.parseLong(pathArray[pathArray.length-1]);
        Uri uri = ContentUris.withAppendedId(MediaStore.Video.Media.getContentUri(pathArray[1]), id);
        try (Cursor cursor = Utils.getApp().getContentResolver().query(uri, projection, null, null, null);
        ) {
            if (cursor != null) {
                int column_index = cursor
                        .getColumnIndexOrThrow(MediaStore.Video.Media.DATA);
                cursor.moveToFirst();
                return cursor.getString(column_index);
            } else {
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
